package com.sc.VenusQueryBeta.presenter.login;

import com.hengjun.kingstar.sdk.utils.LogUtils;
import com.sc.VenusQueryBeta.contract.login.NextRegistContract;
import com.sc.VenusQueryBeta.model.bean.login.ComfirmRegistrationBean;
import com.sc.VenusQueryBeta.model.bean.login.RegistBean;
import com.sc.VenusQueryBeta.model.login.NextRegistModel;

import io.reactivex.functions.Consumer;

/**
 * Created by Administrator on 29/9/2018.
 *
 */

public class NextRegistPresenter extends NextRegistContract.NextPresenter {
    @Override
    protected NextRegistContract.INextModel getModel() {
        return NextRegistModel.newInstance();
    }

    @Override
    public void onStart() {
    }

    /**
     * 实例化对象
     * @return fs
     */
    public static NextRegistPresenter newInstance(){
        return new NextRegistPresenter();
    }

    /**
     * 註冊
     * @param id
     * @param smsCode
     * @param password
     * @param clientUID
     * @param deviceUID
     * @param deviceType
     * @param areaCode
     */
    @Override
    public void register(String id, String smsCode, String password, String clientUID, String deviceUID, String deviceType, String areaCode) {
        //        if (mIView == null || mIModel == null) {
//            return;
//        }
        mRxManager.register(mIModel.regist(id,smsCode,password,clientUID,deviceUID,deviceType,areaCode).subscribe(new Consumer<RegistBean>() {
            @Override
            public void accept(RegistBean registBean) throws Exception {
//                if (mIView != null){
//                    LogUtils.e("SDDASQWEQWEQW");
//                    return;
//                }
                mIView.returnRegistSuccess(registBean);
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                LogUtils.e("accept");
//                if (mIView != null)
//                    return;
                mIView.showToast("Network error.");
                mIView.showNetworkError();
            }
        }));
    }

    @Override
    public void confirmRegister(String id, String smsCode, String password, String clientUID, String deviceUID, String deviceType) {
        mRxManager.register(mIModel.confirmRegist(id,smsCode,password,clientUID,deviceUID,deviceType).subscribe(new Consumer<ComfirmRegistrationBean>() {
            @Override
            public void accept(ComfirmRegistrationBean comfirmRegistrationBean) throws Exception {
//                if (mIView != null){
//                    LogUtils.e("SDDASQWEQWEQW");
//                    return;
//                }
                mIView.returnConfirmRegistSuccess(comfirmRegistrationBean);
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                LogUtils.e("accept");
//                if (mIView != null)
//                    return;
                mIView.showToast("Network error.");
                mIView.showNetworkError();
            }
        }));
    }
}
